//
//  BBWebViewController.m
//  BlockBrowser
//
//  Created by Mac on 2018/4/24.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "BBWebViewController.h"
@interface BBWebViewController()<UIWebViewDelegate>
@end
@implementation BBWebViewController
- (UIWebView *)webView{
    if (!_webView) {
        _webView = [[UIWebView alloc] initWithFrame:UIScreenFrame];
        _webView.backgroundColor = [UIColor whiteColor];
        _webView.delegate = self;
        _webView.opaque = NO;
    }
    return _webView;
}
- (void)setUrlStr:(NSString *)urlStr{
    _urlStr = urlStr;
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
    if (BBThemeColorManger.isBlack) {
        [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.style.backgroundColor=\"black\""];
        // 改变网页内容文字颜色
        [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTextFillColor=\"gray\""];
    }

    [self.webView reload];
}
- (void)setForceTitle:(NSString *)forceTitle{
    _forceTitle = forceTitle;
    self.title = _forceTitle;
}
#pragma mark --vc 生命周期
- (void)viewDidLoad{
    [super viewDidLoad];
     [TMUtils sendGetLookAwardRequest];
    [self.view addSubview:self.webView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    if (BBThemeColorManger.isBlack) {
        [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.style.backgroundColor=\"black\""];
        // 改变网页内容文字颜色
        [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTextFillColor=\"gray\""];
    }
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    
}
@end
